home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / handline.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  153 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    handline -
  19.  *        Human line code follows
  20.  *
  21.  *                Paul Haeberli - 1991
  22.  */
  23. #include "vect.h"
  24.  
  25. static humanline();
  26. static distort();
  27. float fnoise3();
  28. float frand();
  29.  
  30. #define NMULTI        (1)
  31. #define MAGMULTI    (0.05)
  32. #define TOLERANCE    (0.000001)
  33.  
  34. static float wobfreq = 1.0;
  35. static float wobmag = 0.0;
  36. static float warpfreq = 1.0;
  37. static float warpmag = 0.0;
  38. static float seglen = 0.2;
  39. static float dropout = 0.2;
  40. static float humanoffsets[NMULTI];
  41.  
  42. handsetwobble(freq,mag)
  43. float freq, mag;
  44. {
  45.     wobfreq = freq;
  46.     wobmag = mag;
  47. }
  48.  
  49. handsetwarp(freq,mag)
  50. float freq, mag;
  51. {
  52.     warpfreq = freq;
  53.     warpmag = mag;
  54. }
  55.  
  56. handsetseglen(len)
  57. float len;
  58. {
  59.     seglen = len;
  60. }
  61.  
  62. handsetdropout(val)
  63. float val;
  64. {
  65.     dropout = val;
  66. }
  67.  
  68. handline(linefunc,v1,v2)
  69. int (*linefunc)();
  70. vect *v1, *v2;
  71. {
  72.     int i;
  73.     float len, temp;
  74.     vect del, sdel, p1, p2;
  75.  
  76.     vsub(v2,v1,&del);
  77.     len = vlength(&del);
  78.     if(len<TOLERANCE)
  79.     return;
  80.     vscale(&del,1.0/len);
  81.     for(i=0; i<NMULTI; i++) {
  82.     sdel = del;
  83.     vscale(&sdel,MAGMULTI*humanoffsets[i]);
  84.     temp = sdel.x;
  85.     sdel.x = -sdel.y;
  86.     sdel.y = temp;
  87.     vadd(v1,&sdel,&p1);
  88.     vadd(v2,&sdel,&p2);
  89.     humanline(linefunc,&p1,&p2,0.0);
  90.     }
  91. }
  92.  
  93. handdown()
  94. {
  95.     int i;
  96.  
  97.     for(i=0; i<NMULTI; i++) {
  98.     /* humanoffsets[i] = frand()-0.5; */
  99.     humanoffsets[i] = 0.0;
  100.     }
  101. }
  102.  
  103. static humanline(linefunc,v1,v2,offset)
  104. int (*linefunc)();
  105. vect *v1, *v2;
  106. float offset;
  107. {
  108.  
  109.     int i, nsegs;
  110.     vect delta, p1, p2, d1, d2;
  111.     float len;
  112.  
  113.     vsub(v2,v1,&delta);
  114.     len = vlength(&delta);
  115.     nsegs = (len/seglen)+1;
  116.     vscale(&delta,1.0/nsegs);
  117.     p1 = *v1;
  118.     for(i=0; i<nsegs; i++) {
  119.     vadd(&p1,&delta,&p2);
  120.     distort(&p1,&d1,offset);
  121.     distort(&p2,&d2,offset);
  122.     if(frand()>=dropout) {
  123.         linefunc(&d1,&d2);
  124.     }
  125.     p1 = p2;
  126.     }
  127. }
  128.  
  129. static distort(v1,v2,offset)
  130. vect *v1, *v2;
  131. float offset;
  132. {
  133.     float dx, dy, cx, cy;
  134.  
  135.     cx = v1->x;
  136.     cy = v1->y;
  137.  
  138.     if(warpmag>0.0) {
  139.     dx = warpmag*fnoise3(0.3*offset+0.0+warpfreq*v1->x,warpfreq*v1->y,0.0);
  140.     dy = warpmag*fnoise3(0.3*offset+5.0+warpfreq*v1->x,warpfreq*v1->y,0.0);
  141.     cx += dx;
  142.     cy += dy;
  143.     }
  144.     if(wobmag>0.0) {
  145.     dx = wobmag*fnoise3(0.3*offset+0.0+wobfreq*v1->x,wobfreq*v1->y,0.0);
  146.     dy = wobmag*fnoise3(0.3*offset+5.0+wobfreq*v1->x,wobfreq*v1->y,0.0);
  147.     cx += dx;
  148.     cy += dy;
  149.     }
  150.     v2->x = cx;
  151.     v2->y = cy;
  152. }
  153.